<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
        #image {
          width: 100px;
          height: 100px;
        }
    </style>
</head>
<body>
<img src="" alt="" id="image" />
<div class="select_photo">选择图片</div>
<script>
    window.jsBridge = window.jsBridge || {};
    window.jsBridge.call = function (method, message, callback) {
      functionName = "win_fun" + ~~(Math.random * 1000); // 注册随机函数
      window[functionName] = function (...arg) {
        callback?.(...arg);
        delete window[functionName];
      };
      if (window.harmonyOS && window.harmonyOS[method]) {
        // 调用原生方法
        window.harmonyOS[method](functionName, message);
      }
    };
    // 请求手机相册
    document.querySelector(".select_photo").onclick = () => {
      jsBridge.call("selectPhoto", "请求相册", (url) => {
        // 原生回调h5传参
        document.querySelector("#image").src = url;
      });
    };
</script>
</body>
</html>
